package com.tonicgb.api.admin.controller;


import com.tonicgb.service.constracts.UploadService;
import com.tonicgb.shared.annotation.ApiResponse;
import com.tonicgb.shared.annotation.PassToken;
import com.tonicgb.shared.common.response.FileResult;

import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author zhaiyujin
 * @date 2021-09-22 15:15:29
 * @说明 文件上传
 */
@Controller
@RequestMapping("${adminPath}/upload")
@Api(tags = "文件上传",description = "文件上传")
public class UploadController {

@Autowired
@Qualifier("local")
private UploadService uploadService;

    @PostMapping(value = "/image",headers = "content-type=multipart/form-data")
    @ApiOperation(value = "图片上传",notes = "由于swagger3.0bug问题 暂时这样处理(此bug导致Knife4j暂不支持喽)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file", dataType = "String",dataTypeClass = String.class,value = "文件", required = true),
            @ApiImplicitParam(name = "model", dataType = "String",dataTypeClass = String.class,paramType = "form", value = "模块 用户,商品,微信,文章,等等你来定"),
            @ApiImplicitParam(name = "pid", dataType = "String",dataTypeClass = String.class,paramType = "form",value = "分类ID 用户,商品,微信,文章,等等你来定", allowableValues = "range[0,1,2,3,4,5,6,7,8,9]")
    })
    @PassToken
    @ApiResponse
    public FileResult uploadImg(@ApiParam(value="文件",required=true)@RequestPart("file") MultipartFile file,@ApiParam(value="模块名") String model,@ApiParam(value="分类id") Integer pid) throws Exception {
            return uploadService.image(file,model,pid);

    }

    @PostMapping(value = "/file" )
    @ApiOperation(value = "文件上传",notes = "由于swagger3.0bug问题 暂时这样处理(此bug导致Knife4j暂不支持喽)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "file",  dataType = "String",dataTypeClass = String.class,value = "文件",  required = true),
            @ApiImplicitParam(name = "model",  dataType = "String", dataTypeClass = String.class,value = "模块 用户,商品,微信,文章,等等你来定"),
            @ApiImplicitParam(name = "pid",  dataType = "String",dataTypeClass = String.class, value = "分类ID 用户,商品,微信,文章,等等你来定", allowableValues = "range[0,1,2,3,4,5,6,7,8,9]")
    })
    @PassToken
    @ApiResponse
    public FileResult uploadFiles(@RequestParam("file")MultipartFile file, String model, Integer pid) throws Exception {
        return uploadService.file(file,model,pid);

    }

}
